package com.yunji.base.business;

import com.yunji.base.convert.SiteLocationTypeConvert;
import com.yunji.base.dto.SiteLocationTypeDTO;
import com.yunji.base.params.SiteLocationTypeParam;
import com.yunji.base.service.SiteLocationService;
import com.yunji.base.service.SiteLocationTypeService;
import com.yunji.base.vo.SiteLocationTypeVO;
import com.yunji.common.enums.common.ErrorEnum;
import io.jsonwebtoken.lang.Assert;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Component
public class SiteLocationTypeBusiness {

    @Resource
    private SiteLocationService siteLocationService;

    @Resource
    private SiteLocationTypeService locationTypeService;

    @Transactional
    public Long create(SiteLocationTypeDTO dto) {
        return locationTypeService.create(SiteLocationTypeConvert.DTOToDO(dto));
    }

    public void update(SiteLocationTypeDTO dto) {
        locationTypeService.update(SiteLocationTypeConvert.DTOToDO(dto));
    }

    public void delete(Long... ids) {
        Assert.isTrue(!siteLocationService.existsLocationType(Arrays.asList(ids)), ErrorEnum.BUSINESS_612007.getText());
        locationTypeService.delete(Arrays.asList(ids));
    }

    public SiteLocationTypeVO getInfo(Long id) {
        return locationTypeService.getInfo(id);
    }

    public List<SiteLocationTypeVO> searchPage(SiteLocationTypeParam params) {
        return locationTypeService.searchPage(params);
    }
}
